<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//Dtd XHTML 1.0 Transitional//EN" "http://www.w3.org/tr/xhtml1/Dtd/xhtml1-transitional.dtd">
<html>
	<head>
		<%@include file="/WEB-INF/page/include/head.jsp"%>
		<title>用户修改页</title>
	</head>
	<body >
		 <s:form action="user_searchList" namespace="/user" method="post" theme="simple">
			 <div align="center" style="width: 400px">
			 	 <table border="1" cellpadding="0" cellspacing="0" align="center" width="100%">
			 	 	<TR>
			 	 		<TD colspan="2">
							<strong>
				 	 			<s:if test="userBean.id>0">
				 	 				修改
				 	 			</s:if>
				 	 			<s:else>
				 	 				添加
				 	 			</s:else>
				 	 			用户
							</strong>
			 	 		</TD>
			 	 	</TR>
			 	 	<TR>
			 	 		<TD>
			 	 			用户名：
			 	 		</TD>
			 	 		<TD>
			 	 			<s:textfield name="userBean.username"/>
			 	 		</TD>
			 	 	</TR>
			 	 	<TR>
			 	 		<TD>
			 	 			密&nbsp;码：
			 	 		</TD>
			 	 		<TD>
			 	 			<s:password name="userBean.password"/>
			 	 		</TD>
			 	 	</TR>
			 	 	<TR>
			 	 		<TD>
			 	 			性&nbsp;别：
			 	 		</TD>
			 	 		<TD>
			 	 			<s:radio name="userBean.sex" id="userBean.sex" list="#{'1':'男','0':'女'}"  theme="simple" />
			 	 		</TD>
			 	 	</TR>
			 	 	<TR>
			 	 		<TD>
			 	 			<input type="button" value="提交" onclick="save()"/>
			 	 		</TD>
			 	 		<TD>
			 	 			<input type="button" value="关闭" onclick="closeWindow();" />
			 	 		</TD>
			 	 	</TR>
			 	 </table>
			 </div>
			 <div>
			 	<s:hidden name="userBean.id"/>
			 </div>
		 </s:form>
<iframe id="waitIframe" frameborder="0" style="width:100%;top:0; left:0;background:#cccccc;border:none; position:absolute; z-index:2; display:none" ></iframe>	
    <div id="apdiv" style="z-index:3;position:absolute; display:none;background:#FFFFFF; border: 1px solid #000000;height: 200px;width: 300px;text-align: center">
		<br/>
		<br/>
		<br/>
		<br/>
		<br/>
		<br/>
		<br/>
		<div>正在执行，请稍等。。。</div>
 </div>		 
		 <script type="text/javascript">
		 	//保存
		 	function save(){
		 		showCustomDiv(true,'apdiv','waitIframe',1);
			 	if(checkData()==true){
				 	var url = '<%=path%>';
				 	url += "/user/user_saveUserBean?tmp=" + Math.round(Math.random()*1000);
				 	var username = $(":input[name='userBean.username']").val();
					var password = $(":input[name='userBean.password']").val();
				 	var param = "userBean.username=" + $.trim(username);
				 	  param += "&userBean.password=" + $.trim(password);
				 	  param += "&userBean.realName=" + $.trim(username);
				 	  param += "&userBean.id=" + $(":input[name='userBean.id']").val();
				 	  param += "&userBean.sex=" + $(":input[name='userBean.sex']").val();
				 	$.ajax({
				 	   type: "POST",
				 	   url: url,
				 	   data: param,
				 	   success: function(msg){
					 	   if(msg=='2'){
						 	   alert("用户名已经存在，请重新填写");
						 	  $(":input[name='userBean.username']").focus();
						   }else if(msg=='-1'){
							   alert("后台异常，请联系管理员");
						   }else if(msg=='1'){
							   alert("保存成功");
							   window.returnValue = '1';
							   closeWindow();  
						   }else if(msg =='0'){
							   alert("名称不能为空");
						   }
					 	  showCustomDiv(false,'apdiv','waitIframe',1);
				 	   }
				 	});
				 }else{
					 showCustomDiv(false,'apdiv','waitIframe',1);
			     }
			}

			//检查 是否 为空
			function checkData(){
				var username = $(":input[name='userBean.username']").val();
				var password = $(":input[name='userBean.password']").val();
				if($.trim(username)==''){
					alert("用户名不能为空");
					 $(":input[name='userBean.username']").focus();
					return false;
				}
				if($.trim(password)==''){
					 alert("密码不能为空");
					 $(":input[name='userBean.password']").focus();
					return false;
				}
				return true;
			}
		 </script>
	</body>
</html>
